//
//  UIImage+Extension.swift
//  1218-图片选择器
//
//  Created by 王先强 on 15/12/18.
//  Copyright © 2015年 王先强. All rights reserved.
//

import UIKit

extension UIImage {
    
    
    func resizePictureFromWith(width: CGFloat) -> UIImage {
        
        if self.size.width < width {
            return self
        }
        
        let height = self.size.height * width / self.size.width
        let rect = CGRectMake(0, 0, width, height)
        
        UIGraphicsBeginImageContext(rect.size)
        
        self.drawInRect(rect)
        
        let image = UIGraphicsGetImageFromCurrentImageContext()
        
        UIGraphicsEndImageContext()
        
        return image
    }
}
